/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.web.misc.license;

import java.util.zip.CRC32;

public abstract class LicenseUtil extends GroupUtil {

    public static short calculateCRC32(String s, int i, byte[] bytes) {
        CRC32 crc32 = new CRC32();
        if (s != null) {
            for (int j = 0; j < s.length(); j++) {
                crc32.update(s.charAt(j));
            }
        }

        crc32.update(i);
        crc32.update(i >> 8);
        crc32.update(i >> 16);
        crc32.update(i >> 24);

        for (int j = 0; j < bytes.length - 2; j++) {
            crc32.update(bytes[j]);
        }

        return (short) (int) crc32.getValue();
    }

    private LicenseUtil() {}
}